package com.freen.fadmin.entity;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.freen.fadmin.util.EntityUtils;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;

//系统entity基类，让实体类去继承时间等字段
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public class SysBaseEntity {
    @Column(name = "created_at")
    @CreatedDate
    private Long createdAt;

    @Column(name = "updated_at")
    @LastModifiedDate
    private Long updatedAt;

    //创建人
    @Column(name = "created_by")
    @CreatedBy
    private String  createdBy;

    @Column(name = "updated_by")
    @LastModifiedBy
    private String updatedBy;

    @JsonSerialize(using = EntityUtils.class)
    public Long getCreatedAt() {
        return createdAt;
    }

    public void setCreatedAt(Long createdAt) {
        this.createdAt = createdAt;
    }

    public String getCreatedBy() {
        return createdBy;
    }

    public void setCreatedBy(String createdBy) {
        this.createdBy = createdBy;
    }
    @JsonSerialize(using = EntityUtils.class)
    public Long getUpdatedAt() {
        return updatedAt;
    }

    public void setUpdatedAt(Long updatedAt) {
        this.updatedAt = updatedAt;
    }

    public String getUpdatedBy() {
        return updatedBy;
    }

    public void setUpdatedBy(String updatedBy) {
        this.updatedBy = updatedBy;
    }
}
